package zh.servers.button;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
 * @author cbz
 * @date 2022/05/23
 * @version 1.2
 * @description: 剪刀石头布
 */
@SuppressWarnings("serial")
public  class conton extends JFrame implements ActionListener {
    JButton jiandao,shitou,bu,clear;
    JPanel panel2,panel1;
    JLabel label;



    public static void main (String []args){
        conton frame=new conton();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);



    }
    public conton (){
        setTitle("石头剪刀布");
        setLocation(250,250);
        setSize(350,350);

        panel1=new JPanel();
        panel1.setBackground(Color.yellow);
        shitou=new JButton("石头");
        jiandao=new JButton("剪刀");
        bu=new JButton("布");
        clear=new JButton("清空");
        panel2=new JPanel();
        panel2.setBackground(Color.red);
        label=new JLabel("输入石头，剪刀，布");


        shitou.addActionListener(this);
        jiandao.addActionListener(this);
        bu.addActionListener(this);
        clear.addActionListener(this);



        panel1.add(shitou);
        panel1.add(jiandao);
        panel1.add(bu);
        panel1.add(clear);
        panel2.add(label);

        add(panel1,BorderLayout.NORTH);
        add(panel2,BorderLayout.CENTER);
    }

    public void actionPerformed(ActionEvent e){
        if(e.getSource()==shitou) {
            int i = ((int) (Math.random() * 10)) % 3;
            switch (i) {
                case 0:
                    label.setText("你出石头，电脑出石头，平局");
                    break;
                case 1:
                    label.setText("你出石头，电脑出剪刀，你赢了");
                    break;
                case 2:
                    label.setText("你出石头，电脑出布，你输了");
                    break;

            }
        }
        else if(e.getSource() == bu){
            int i = ((int)(Math.random()*10))%3;
            switch(i) {
                case 0:
                    label.setText("你出布，电脑出石头，恭喜你赢了！");
                    break;
                case 1:
                    label.setText("你出布，电脑出剪刀，很遗憾你输了！");
                    break;
                case 2:
                    label.setText("你出布，电脑出布，平局！");
                    break;
            }
        }else if(e.getSource() == clear) {
            label.setText("选择剪刀, 石头, 布开始游戏！");
        }
    }

}
